package com.qf.web;

import com.alibaba.fastjson.JSON;
import com.qf.web.common.R;
import com.qf.web.service.StudentService;
import com.qf.web.service.impl.StudentServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/deleteStudent")
public class DeleteStudentServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String id = req.getParameter("id");
        StudentService studentService = new StudentServiceImpl();
        int result = studentService.deleteStudentById(Integer.parseInt(id));
        if (result == 1) {
            System.out.println("删除成功");

            R r1 = new R();
            R r = r1.ok(0, "删除成功");
            String s = JSON.toJSONString(r);
            resp.getWriter().println(r);
        }
    }
}
